package com.xtayfjpk.resteasy.test;

import java.io.File;

import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
import org.eclipse.jetty.plus.webapp.PlusConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.FragmentConfiguration;
import org.eclipse.jetty.webapp.MetaInfConfiguration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebInfConfiguration;
import org.eclipse.jetty.webapp.WebXmlConfiguration;

public class Launcher {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		String userDir = System.getProperty("user.dir");
		File webapp = new File(userDir, "src/main/webapp");
		System.out.println(webapp);
		String contextPath = userDir.substring(userDir.lastIndexOf(File.separator) + 1);
		System.out.println(contextPath);

		Server server = new Server(9090);



		WebAppContext webAppContext = new WebAppContext(webapp.getAbsolutePath(), "/" + contextPath);

		// 必须添加AnnotationConfiguration配置方式才能扫描注解
		/*webAppContext.setConfigurations(new Configuration[]{new AnnotationConfiguration(),
				new WebXmlConfiguration(), new WebInfConfiguration(),
				new PlusConfiguration(), new MetaInfConfiguration(),
	            new FragmentConfiguration(), new EnvConfiguration()});*/
		//webAppContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/bin/");

		HandlerCollection handlers = new HandlerCollection();
		handlers.addHandler(webAppContext);
		server.setHandler(handlers);

		server.start();

	}

}
